package org.xs.web.http;

import java.io.IOException;

import org.xs.web.http.provider.HTTPHeader;
import org.xs.web.http.provider.HTTPResponse;

public class RedirectResponse implements XSResponse{
	private int code = 301;
	private String url;
	
	public RedirectResponse(String url){
		this.url = url;
	}
	
	@Override
	public int getCode() {
		return code;
	}

	@Override
	public String getContentType() {
		return null;
	}

	@Override
	public HTTPHeader[] getHeaders() {
		return null;
	}

	@Override
	public boolean isJs() {
		return false;
	}

	@Override
	public boolean isStream() {
		return false;
	}

	@Override
	public boolean isTemplete() {
		return false;
	}

	@Override
	public boolean isText() {
		return false;
	}

	@Override
	public boolean isXml() {
		return false;
	}

	@Override
	public Object apply(HTTPResponse response) {
		try {
			response.setStatus(code);
			response.getDelegate().sendRedirect(url);
		} catch (IOException e) {
			 
		}
		return true;
	}

}
